<template>
  <div>
    <!-- 我的收藏 -->
    <van-nav-bar
      title="我的收藏"
      left-text="返回"
      left-arrow
      @click-left="onClickLeft"
    />
    <!-- {{myCollections[0]}} -->
    <div>
      <div>收藏夹&nbsp;{{ myCollections.length }}个内容</div>
      <div v-for="item in myCollections" :key="item">
        <div class="box">
          <div>
            {{ $moment(parseInt(item.create_time)).format("YYYY-MM-DD HH:mm") }}
          </div>
          <div>{{ item.content }}</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
// import dycard from '../../components/dyCard'
import axios from "axios";
export default {
  components: {},
  data() {
    return {
      myCollections: [],
      length: "",
    };
  },
  created() {
    this.getMyCollections();
  },
  methods: {
    onClickLeft() {
      this.$router.go(-1);
    },
    getMyCollections() {
      axios
        .get(
          `http://localhost:8888/favorites/findAll?username=${sessionStorage.getItem(
            "username"
          )}`
        )
        .then((res) => {
          console.log(res);
          for (var item of res.data) {
            axios
              .get(
                `http://localhost:8888/movie/comment/findById?id=${item.collect_comment}`
              )
              .then((res) => {
                console.log(res);
                this.length = this.myCollections.push(res.data[0]);
              });
          }
        });
    },
  },
};
</script>

<style>
.box {
  font-size: 13px;
  line-height: 1.5rem;
}
</style>
